package com.getpebble.android.framework.protocol.inbound;

import com.getpebble.android.bluetooth.protocol.ProtocolMessage;
import com.getpebble.android.framework.appmessage.AppMessage;
import com.getpebble.android.framework.appmessage.AppMessage.AppMessageCommand;
import com.getpebble.android.framework.appmessage.BinaryPebbleDictionary;
import com.getpebble.android.framework.appmessage.PebbleDictionary;
import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.util.ByteUtils;
import java.nio.ByteBuffer;
import java.util.UUID;

public class PblInboundAppMessage extends PblInboundMessage {
    private AppMessage mAppMessage;

    public PblInboundAppMessage(ProtocolMessage message) {
        super(message);
        ByteBuffer buffer = message.getDataBuffer();
        AppMessageCommand command = AppMessageCommand.fromByte(buffer.get());
        byte transactionId = buffer.get();
        UUID uuid = null;
        PebbleDictionary pebbleDictionary = null;
        if (!(command == AppMessageCommand.ACK || command == AppMessageCommand.NACK)) {
            uuid = ByteUtils.bytes2uuid(buffer);
            pebbleDictionary = BinaryPebbleDictionary.fromByteBuffer(buffer);
        }
        this.mAppMessage = new AppMessage(transactionId, uuid, command, pebbleDictionary);
    }

    public AppMessage getAppMessage() {
        return this.mAppMessage;
    }

    EndpointId getId() {
        return EndpointId.APP_MESSAGE;
    }

    protected int getMinSize() {
        return 2;
    }
}
